package design.graduation.novelwebsite.model.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import design.graduation.novelwebsite.constant.Constant;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author: 洪少尉
 * @Date: 2020/4/20 15:08
 * @Description:  装载返回前端Json数据
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultObj implements Serializable {
	/**
	 * 状态码
	 */
	private Integer code = Constant.SUCCESS_CODE;
	/**
	 * 状态信息
	 */
	private String msg ="";
	/**
	 * 数据
	 * 实体类与json互转的时候 属性值为null的不参与序列化
	 */
	@JsonInclude(JsonInclude.Include.NON_NULL)
	private Object data;

	/**
	 * 构造状态码、状态信息
	 * @param code :状态码
	 * @param msg :状态信息
	 */
	public ResultObj(Integer code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	/**
	 * 默认成功
	 * @param data 返回数据
	 */
	public ResultObj(Object data) {
		this.data = data;
	}
}
